﻿using PMS.Services.Authentication.Externel;
using PMS.Services.EntityServices.Settings;
using PMS.Services.Plugins;
using PMS.Services.Utils;

namespace PMS.Plugin.ExternalAuth.DingTalkScan
{
    /// <summary>
    /// Represents method for the authentication with DingdingTalk account
    /// 使用钉钉提供的扫码登录页面
    /// </summary>
    public class DingTalkScanAuthenticationMethod : BasePlugin, IExternalAuthenticationMethod
    {
        #region Fields

        private readonly ISettingService _settingService;
        private readonly IWebHelper _webHelper;

        #endregion

        #region Ctor

        public DingTalkScanAuthenticationMethod(ISettingService settingService, IWebHelper webHelper)
        {
            _settingService = settingService;
            _webHelper = webHelper;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Gets a configuration page URL
        /// </summary>
        public override string GetConfigurationPageUrl()
        {
            return $"{_webHelper.GetStoreLocation()}backend/dingtalkscanauthentication/configure";
        }

        /// <summary>
        /// Gets a name of a view component for displaying plugin in public store
        /// </summary>
        /// <returns>View component name</returns>
        public string GetPublicViewComponentName()
        {
            return DingTalkScanAuthenticationDefaults.VIEW_COMPONENT_NAME;
        }

        public string GetProviderSystemName()
        {
            return DingTalkScanAuthenticationDefaults.SystemName;
        }

        public string GetPluginDisplayName()
        {
            return DingTalkScanAuthenticationDefaults.PluginDisplayName;
        }
        /// <summary>
        /// Install the plugin
        /// </summary>
        public override void Install()
        {
            //settings
            _settingService.SaveSetting(new DingTalkScanExternalAuthSettings());

            base.Install();
        }

        /// <summary>
        /// Uninstall the plugin
        /// </summary>
        public override void Uninstall()
        {
            //settings
            _settingService.DeleteSetting<DingTalkScanExternalAuthSettings>();

            base.Uninstall();
        }

        #endregion
    }

}
